package svgedit.svg;

/**
 * The root group is used to represent the group functions of the SVG's document
 * root. It exists once, in an SVGDocument (called root). This class mainly
 * exists to conveniently override functions of SVGGroup that need to behave
 * differently in the root element. eg. ungroup() we never want that to do
 * anything.
 */
public class SVGRootGroup extends SVGGroup
{

	private SVGDocument document;

	/**
	 * Creates the root group which only ever exists once, inside the root of
	 * the SVGDocument
	 * 
	 * @see svgedit.svg.SVGDocument
	 * @see svgedit.svg.SVGGroup
	 * @param document
	 *            the document
	 */
	public SVGRootGroup(SVGDocument document)
	{
		super(((SVGGroup) null));
	}

	@Override
	public SVGDocument getDocument()
	{
		return this.document;
	}

	@Override
	public SVGRootGroup getRootGroup()
	{
		return this;
	}

	@Override
	public SVGGroup getParent()
	{
		return this;
	}

	@Override
	public void destroy()
	{
		for (SVGElementInterface e : this)
			e.destroy();
	}

	public void write(int indent)
	{
		if (indent < 0)
			indent = 0;
		System.out.printf("%" + indent + "s", " ");
		System.out.printf("<svg id='%s'>\n", this.toString());
		this.writeChildren(indent);
		System.out.printf("%" + indent + "s</svg>\n", " ");
	}

	@Override
	public void ungroup()
	{
		// we should never get here
		System.err.println("SVGRootGroup.ungroup() Cant UNGROUP the ROOT");
	}

}
